# 进制转换算法
#   divideBy2十进制转二进制
#   十进制转换二进制,八进制,十六进制
import os, sys

# 把包的父目录添加到系统搜索路径
BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

from base_data_structures.stack import Stack

def divideBy2(decNumber):
    remstack = Stack()

    # 采用除2取余的方法, 并将余数压栈
    while decNumber > 0:
        rem = decNumber % 2
        remstack.push(rem)
        decNumber = decNumber // 2

    # 利用栈的FILO特性产生二进制返回值
    binString = ''
    while not remstack.isEmpty():
        binString += str(remstack.pop())

    return binString

def baseConverter(decNumber, base):
    digits = '0123456789ABCDEF'
    remstack = Stack()

    while decNumber > 0:
        rem = decNumber % base
        remstack.push(rem)
        decNumber = decNumber // base

    newString = ''
    while not remstack.isEmpty():
        newString += digits[remstack.pop()]

    return newString

print(baseConverter(233, 16))

    